Skip to content

Add Clickable mock#4055

Open
m-bert wants to merge 1 commit intomainfrom
@mbert/clickable-mock
Open

Add Clickable mock#4055
m-bert wants to merge 1 commit intomainfrom
@mbert/clickable-mock

Conversation

@m-bert
Copy link
Copy Markdown
Contributor

@m-bert m-bert commented Apr 3, 2026

Description

This PR adds mock for Clickable component

Test plan

import { fireEvent, render } from '@testing-library/react-native';
import { Text } from 'react-native';
import { Clickable } from '../mocks/GestureButtons';

test('Trigger press by text', () => {
  const onPress = jest.fn();
  const { getByText } = render(
    <Clickable activeOpacity={0.3} onPress={onPress}>
      <Text>Press Me</Text>
    </Clickable>
  );

  fireEvent.press(getByText('Press Me'));

  expect(onPress).toHaveBeenCalled();
});

Copilot AI review requested due to automatic review settings April 3, 2026 10:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Jest mock export for the Clickable component within the gesture button mocks, intended to simplify testing usage of Clickable in environments using the library’s mocks.

Changes:

  • Export Clickable from src/mocks/GestureButtons.tsx as an alias of RawButton.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 9 to +11
export const RectButton = RawButton;
export const BorderlessButton = TouchableNativeFeedback;
export const Clickable = RawButton;
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clickable is a v3 export (src/v3/components/index.ts -> src/v3/components/Clickable/Clickable), but this mock file is used to mock ./src/components/GestureButtons (legacy) in jestSetup.js. Exporting Clickable here likely won’t affect import { Clickable } from 'react-native-gesture-handler' in tests, so the PR may not actually provide a Jest mock for the public Clickable API. Consider adding a dedicated v3 Clickable mock and wiring it up in jestSetup.js (e.g., mock ./src/v3/components/Clickable/Clickable or ./src/v3/components).

Copilot uses AI. Check for mistakes.
export const BaseButton = RawButton;
export const RectButton = RawButton;
export const BorderlessButton = TouchableNativeFeedback;
export const Clickable = RawButton;
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clickable’s onPress callback in the real implementation receives a pointerInside: boolean (same as BaseButtonProps), but this mock delegates directly to TouchableNativeFeedback, which calls onPress with a press event object. This API mismatch can cause consumer tests to pass in Jest but break in production (or vice versa) when callbacks rely on the boolean argument. Consider wrapping the handler in the mock to call onPress?.(true) (and similarly map onLongPress, onPressIn, onPressOut if you want closer parity).

Suggested change
export const Clickable = RawButton;
export const Clickable = ({
onPress,
onLongPress,
onPressIn,
onPressOut,
...rest
}: any) => (
<RawButton
{...rest}
onPress={() => onPress?.(true)}
onLongPress={() => onLongPress?.(true)}
onPressIn={() => onPressIn?.(true)}
onPressOut={() => onPressOut?.(true)}
/>
);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants